Skip to content

Replace moment.js with native Date/Intl APIs#6404

Merged
lkostrowski merged 6 commits intomainfrom
lkostrowski/replace-moment-native
Mar 11, 2026
Merged

Replace moment.js with native Date/Intl APIs#6404
lkostrowski merged 6 commits intomainfrom
lkostrowski/replace-moment-native

Conversation

@lkostrowski
Copy link
Member

Scope of the change

Replace moment.js with native JavaScript Date and Intl APIs in 4 trivially replaceable cases. This reduces dependency on a deprecated library while maintaining equivalent functionality.

Changes:

  • TaxAppLabel: use Intl.DateTimeFormat with user locale for date display

  • useNewUserCheck: use native Date for validation and comparison

  • handlers (preorder): use native Date for past-date check

  • GiftCard utils: use native Date for expiry comparison

  • Add TaxAppLabel unit tests for date formatting

  • I confirm I added ripples for changes (see src/ripples) or my feature doesn't contain any user-facing changes

  • I used analytics "trackEvent" for important events

Note: Other moment.js usages in the codebase remain unchanged (12+ files still depend on moment).

@lkostrowski lkostrowski requested a review from a team as a code owner March 9, 2026 19:52
@changeset-bot
Copy link

changeset-bot bot commented Mar 9, 2026

🦋 Changeset detected

Latest commit: 75cbd58

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes a few moment.js usages and replaces them with native Date/Intl APIs to reduce reliance on a deprecated dependency, plus adds a unit test around TaxAppLabel date formatting.

Changes:

  • Replace moment with native Date comparisons in useNewUserCheck, preorder handlers, and gift card expiry logic.
  • Update TaxAppLabel to format dates via Intl.DateTimeFormat using the user locale.
  • Add TaxAppLabel unit tests and a changeset entry.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/welcomePage/WelcomePageOnboarding/hooks/useNewUserCheck.ts Swaps moment parsing/comparison for native Date parsing and > comparison.
src/taxes/components/TaxAppLabel.tsx Replaces moment(created).format(...) with Intl.DateTimeFormat(locale).format(...).
src/taxes/components/TaxAppLabel.test.tsx Adds unit coverage for localized date rendering and conditional sections.
src/products/utils/handlers.ts Replaces moment-based preorder end-date validation with native Date comparison.
src/giftCards/GiftCardUpdate/providers/GiftCardDetailsProvider/utils.ts Replaces moment-based expiry check with native Date comparison.
.changeset/plenty-peaches-agree.md Adds a changeset entry for the moment removal.

@codecov
Copy link

codecov bot commented Mar 9, 2026

Codecov Report

❌ Patch coverage is 60.00000% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 43.19%. Comparing base (142b8cf) to head (75cbd58).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/taxes/components/TaxAppLabel.stories.tsx 0.00% 6 Missing ⚠️
...ders/GiftCardListProvider/GiftCardListProvider.tsx 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             main    #6404     +/-   ##
=========================================
  Coverage   43.18%   43.19%             
=========================================
  Files        2526     2527      +1     
  Lines       44061    44074     +13     
  Branches    10400    10401      +1     
=========================================
+ Hits        19027    19037     +10     
+ Misses      24993    23715   -1278     
- Partials       41     1322   +1281     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

witoszekdev
witoszekdev previously approved these changes Mar 10, 2026
witoszekdev
witoszekdev previously approved these changes Mar 11, 2026
lkostrowski and others added 4 commits March 11, 2026 11:28
- TaxAppLabel: use Intl.DateTimeFormat with user locale for date display
- useNewUserCheck: use native Date for validation and comparison
- handlers (preorder): use native Date for past-date check
- GiftCard utils: use native Date for expiry comparison
- Add TaxAppLabel unit tests

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 11, 2026 10:29
@lkostrowski lkostrowski force-pushed the lkostrowski/replace-moment-native branch from d16a500 to c6d484a Compare March 11, 2026 10:29
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Comment on lines +14 to +18
const dateTimeString = new Intl.DateTimeFormat(locale, {
year: "numeric",
month: "2-digit",
day: "2-digit",
}).format(new Date(created));
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new Date(created) passed into Intl.DateTimeFormat(...).format(...) will throw a RangeError: Invalid time value if created is not a valid date string, which would crash the label render. Consider validating the parsed Date (e.g., isNaN(date.getTime())) and either skipping rendering or falling back to a safe placeholder when invalid.

Suggested change
const dateTimeString = new Intl.DateTimeFormat(locale, {
year: "numeric",
month: "2-digit",
day: "2-digit",
}).format(new Date(created));
const date = new Date(created);
if (isNaN(date.getTime())) {
return "";
}
const dateTimeString = new Intl.DateTimeFormat(locale, {
year: "numeric",
month: "2-digit",
day: "2-digit",
}).format(date);

Copilot uses AI. Check for mistakes.
Comment on lines +22 to +23
// Reset time, so timezone will not flip the day
const thresholdDate = new Date(`${thresholdDateString}T00:00:00`);
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thresholdDateString is treated as a plain date and you append T00:00:00 unconditionally. If the env var is ever set to an ISO datetime (contains T/timezone), this will produce an invalid date and make all users evaluate as not new. Consider parsing the env value as-is when it already includes a time component, and only appending T00:00:00 for date-only values.

Suggested change
// Reset time, so timezone will not flip the day
const thresholdDate = new Date(`${thresholdDateString}T00:00:00`);
// Reset time, so timezone will not flip the day for date-only values.
// If the env var already includes a time component (e.g. full ISO datetime),
// parse it as-is to avoid creating an invalid date string.
const thresholdDate = thresholdDateString.includes("T")
? new Date(thresholdDateString)
: new Date(`${thresholdDateString}T00:00:00`);

Copilot uses AI. Check for mistakes.
@lkostrowski lkostrowski requested a review from witoszekdev March 11, 2026 13:43
Copilot AI review requested due to automatic review settings March 11, 2026 13:59
@lkostrowski lkostrowski merged commit 659142b into main Mar 11, 2026
19 checks passed
@lkostrowski lkostrowski deleted the lkostrowski/replace-moment-native branch March 11, 2026 14:04
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

export function getExtendedGiftCard<T extends GiftCardBase>(
giftCard?: T,
): ExtendedGiftCard<T> | undefined {
// todo do not accept optional value, check for existence higher
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inline note // todo ... should be normalized to the repo’s TODO: convention (and ideally include a tracking reference) so it can be found by tooling and won’t get forgotten.

Suggested change
// todo do not accept optional value, check for existence higher
// TODO: do not accept optional value; check for existence higher

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants